{extend name="public:base" /}
{block name="css"}
<link href="/static/laydate/theme/default/laydate.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/css/select2.min.css" rel="stylesheet"/>
{/block}
{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h3>总订单金额：{$all_pay_price}元</h3>
                </div>

                <div class="ibox-content">
                    <div class="row search-form">
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请选择开始日期" type="text" name="start_time" value="{:input('start_time')}" class="form-control form-control-lg screen-date" readonly>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请选择结束日期" type="text" name="end_time" value="{:input('end_time')}" class="form-control form-control-lg screen-date" readonly>
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="region_id" id="region_id" class="form-control form-control-lg">
                                    <option value="0">请选择区域</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="shop_id" id="shop_id" class="form-control form-control-lg">
                                    <option value="0">请选择门店</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <style>
                                    .select2-container--default .select2-selection--single{
                                        background-color: #fff;
                                        border: 1px solid #e5e6e7;
                                        border-radius: 4px;
                                    }
                                </style>
                                <select name="user_id" class="form-control form-control-lg" id="select2">
                                    <option value="0">请选择会员</option>
                                    {volist name="user_list" id="vo"}
                                    <option value="{$vo.id}" {$vo.id == input('user_id') ? 'selected' : ''}>{$vo.username} / {$vo.mobile}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="meal_status" class="form-control form-control-lg">
                                    <option value="">请选择订单状态</option>
                                    <option value="1" {:input('meal_status') == 1 ? 'selected' : ''}>待付款</option>
                                    <option value="2" {:input('meal_status') == 2 ? 'selected' : ''}>进行中</option>
                                    <option value="3" {:input('meal_status') == 3 ? 'selected' : ''}>已完成</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <button type="button" class="btn btn-primary btn-lg screen-btn">搜索</button>
                                <button type="button" class="btn btn-primary btn-lg excel-btn">导出</button>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>会员昵称</th>
                                <th>会员手机号</th>
                                <th>门店</th>
                                <th>订单号</th>
                                <th>总金额</th>
                                <th>支付金额</th>
                                <th>订单状态</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.username}</td>
                                <td>{$vo.mobile}</td>
                                <td>{$vo.shop_name}</td>
                                <td>{$vo.order_sn}</td>
                                <td>{$vo.all_price}</td>
                                <td>{$vo.pay_price}</td>
                                <td>{$vo.meal_status_text}</td>
                                <td>{:timeFormat($vo.create_time)}</td>
                                <td class="project-actions">
                                    <a href="{:url('doMealOrder', ['id' => $vo.id])}" class="btn btn-white btn-sm">
                                        <i class="iconfont icon-edit"></i> 详情
                                    </a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {if !empty($list)}{$list->render()}{/if}
                    </div>

                </div>
            </div>
        </div>

    </div>

    <div class="modal inmodal" id="myModal3" tabindex="-1" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" onclick="modelClose()"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">订单改价</h4>
                </div>
                <div class="modal-body">
                    <input type="number" class="form-control pay_price" placeholder="请输入金额">
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-white" onclick="modelClose()">关闭</button>
                    <button type="button" class="btn btn-primary" id="confirm">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script src="/static/laydate/laydate.js"></script>

<script src="__STATIC__/jquery/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>
<script>
    laydate.render({
        elem: '.screen-date' //指定元素
    });

    $('#select2').select2()

    var id = 0;

    function getOrderInfo(order_id, pay_price){
        id = order_id;
        $('#myModal3 .pay_price').val(pay_price);
    }

    function modelClose() {
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
        $('#myModal3').css('display', 'none').removeClass('show');
        id = 0;
    }

    $('#confirm').click(function () {
        var pay_price = $('.pay_price').val();

        var url = "/admin/manage/changePayPrice";
        $.post(url, {
            id, pay_price
        }, function (res) {
            layer.msg(res.msg)
            if (res.result == 1) {
                modelClose();
                window.location.reload();
            }
        }, 'json')
    })


    // 区域-门店 联动
    var region_list = `{:getRegionToShop()}` ? JSON.parse(`{:getRegionToShop()}`) : [];
    var region_id = `{:input('region_id')}` ? parseInt(`{:input('region_id')}`) : 0;
    var shop_id = `{:input('shop_id')}` ? parseInt(`{:input('shop_id')}`) : 0;

    if (region_list.length) {
        var option = `<option value="0">请选择区域</option>`;
        region_list.forEach(val => {
            var selected = region_id == val.id ? 'selected' : '';
            option += `<option value="${val.id}" ${selected}>${val.name}</option>`;
        })
        $('#region_id').html(option)
    }

    if (region_id) {
        var option = `<option value="0">请选择门店</option>`;
        for (var i = 0; i < region_list.length; i++) {
            if (region_list[i].id == region_id) {
                var shop_list = region_list[i].shop_list;
                if (shop_list.length) {
                    shop_list.forEach(val => {
                        var selected = val.id == shop_id ? 'selected' : '';
                        option += `<option value="${val.id}" ${selected}>${val.name}</option>`;
                    })
                }
                $('#shop_id').html(option);
                break;
            }
        }
        $('#shop_id').html(option);
    }

    $('#region_id').on('change', function () {
        var id = $(this).val();
        var option = `<option value="0">请选择门店</option>`;
        if (id > 0) {
            for (var i = 0; i < region_list.length; i++) {
                var region_id = region_list[i].id;
                if (id == region_id) {
                    var shop_list = region_list[i].shop_list;
                    if (shop_list.length) {
                        shop_list.forEach(val => {
                            option += `<option value="${val.id}">${val.name}</option>`;
                        })
                    }
                    $('#shop_id').html(option);
                    break;
                }
            }
        } else {
            $('#shop_id').html(option);
        }
    })
</script>
{/block}

